import { constantRoutes, asyncRoutes } from '@/router'

export default {
  namespaced: true,
  state() {
    return {
      routes: [...constantRoutes]
    }
  },
  mutations: {
    setRoutes(state, data) {
      state.routes = [...constantRoutes, ...data]
    }
  },
  actions: {
    filterRoutes(context, menus) {
      const userAsyncRoutes = []
      asyncRoutes.forEach(item => {
        if (menus.includes(item.name)) {
          return userAsyncRoutes.push(item)
        }
      })
      context.commit('setRoutes', userAsyncRoutes)
      return userAsyncRoutes
    }
  }
}
